var _data = {};

$(function(){
  console.log(1)
  console.log('哈哈')

  // $('#frm_title').text((location.search.match(/title=([\w\-]+)/) ? RegExp.$1 : ''));
  $('#frm_title').text(decodeURIComponent(getQueryStringByName('title')));

  $.ajax({
      url: _url_TextBoxTag,
      type: 'GET',
      dataType: 'json',
  }).done(function (data){
    console.log(data)
    // console.log(data[0].item_enname)
    // $("#sel_name").html("");
    // $("#sel_name").append($("<option value=\"\">请选择</option>"));
    // for(var i=0; i<data.length; i++){
    //   $("#sel_name").append($("<option value=\""+data[i].item_enname+"\">"+data[i].item_name+"</option>"));
    // }

    // _data.TextBoxTag = "<option value=''>请选择</option>"

    if("1" !== data.code) return alert(data.msg);

    data = data.itemList;

    _data.TextBoxTag = '';

    for(var i=0; i<data.length; i++){
      _data.TextBoxTag += "<option value='"+ data[i].itemEnName +"'>"+ data[i].itemName +"</option>";
    }

    console.log(_data)
  });

  $.ajax({
      url: _url_TextAreaBoxTag,
      type: 'GET',
      dataType: 'json',
  }).done(function (data){

    if("1" !== data.code) return alert(data.msg);

    data = data.itemList;

    _data.TextAreaBoxTag = '';

    for(var i=0; i<data.length; i++){
      _data.TextAreaBoxTag += "<option value='"+ data[i].itemEnName +"'>"+ data[i].itemName +"</option>";
    }

    console.log(_data)
  });

  $.ajax({
      url: _url_HiddenBoxTag,
      type: 'GET',
      dataType: 'json',
  }).done(function (data){

    if("1" !== data.code) return alert(data.msg);

    data = data.itemList;

    _data.HiddenBoxTag = '';

    for(var i=0; i<data.length; i++){
      _data.HiddenBoxTag += "<option value='"+ data[i].itemEnName +"'>"+ data[i].itemName +"</option>";
    }

    console.log(_data)
  });


  // 
  $.ajax({
      url: _url_SelectBoxTag,
      type: 'GET',
      dataType: 'json',
  }).done(function (data){

    if("1" !== data.code) return alert(data.msg);

    data = data.itemList;

    _data.SelectBoxTag = '';

    for(var i=0; i<data.length; i++){
      _data.SelectBoxTag += "<option value='"+ data[i].itemEnName +"'>"+ data[i].itemName +"</option>";
    }

    console.log(_data)
  });


  // 
  $.ajax({
      url: _url_RadioBoxTag,
      type: 'GET',
      dataType: 'json',
  }).done(function (data){

    if("1" !== data.code) return alert(data.msg);

    data = data.itemList;

    _data.RadioBoxTag = '';

    for(var i=0; i<data.length; i++){
      _data.RadioBoxTag += "<option value='"+ data[i].itemEnName +"'>"+ data[i].itemName +"</option>";
    }

    console.log(_data)
  });


  // 
  $.ajax({
      url: _url_CheckBoxTag,
      type: 'GET',
      dataType: 'json',
  }).done(function (data){

    if("1" !== data.code) return alert(data.msg);

    data = data.itemList;

    _data.CheckBoxTag = '';

    for(var i=0; i<data.length; i++){
      _data.CheckBoxTag += "<option value='"+ data[i].itemEnName +"'>"+ data[i].itemName +"</option>";
    }

    console.log(_data)
  });

  // 
  $.ajax({
      url: _url_DateBoxTag,
      type: 'GET',
      dataType: 'json',
  }).done(function (data){

    if("1" !== data.code) return alert(data.msg);

    data = data.itemList;

    _data.DateBoxTag = '';

    for(var i=0; i<data.length; i++){
      _data.DateBoxTag += "<option value='"+ data[i].itemEnName +"'>"+ data[i].itemName +"</option>";
    }

    console.log(_data)
  });

  // 
  $.ajax({
      url: _url_dataSource,
      type: 'GET',
      dataType: 'json',
  }).done(function (data){

    if("1" !== data.code) return alert(data.msg);

    data = data.selectList;

    _data.dataSource = '';

    for(var i=0; i<data.length; i++){
      _data.dataSource += "<option value='"+ data[i].sourcecontent +"'>"+ data[i].sourcename +"</option>";
    }

    console.log(_data)
  });

  // 
  $.ajax({
      url: _url_formEvent,
      type: 'GET',
      dataType: 'json',
  }).done(function (data){

    if("1" !== data.code) return alert(data.msg);

    data = data.eventList;

    _data.xml_onclick_func = '';

    for(var i=0; i<data.length; i++){
      _data.xml_onclick_func += "<option value='"+ data[i].sourceurl +"'>"+ data[i].sourcename +"</option>";
    }

    $("#xml_onclick_func").html("");
    $("#xml_onclick_func").append($("<option value=''>请选择</option>"));
    $("#xml_onclick_func").append($(_data.xml_onclick_func));

    console.log(_data)
  });

  // 
  $.ajax({
      url: _url_DividerBoxTag,
      type: 'GET',
      dataType: 'json',
  }).done(function (data){

    if("1" !== data.code) return alert(data.msg);

    data = data.eventList;

    _data.DividerBoxTag = '';

    for(var i=0; i<data.length; i++){
      _data.DividerBoxTag += "<option value='"+ data[i].sourceurl +"'>"+ data[i].sourcename +"</option>";
    }

    console.log(_data)
  });

  // 
  $.ajax({
      url: _url_UploadifyBoxTag,
      type: 'GET',
      dataType: 'json',
  }).done(function (data){

    if("1" !== data.code) return alert(data.msg);

    data = data.itemList;

    _data.UploadifyBoxTag = '';

    for(var i=0; i<data.length; i++){
      _data.UploadifyBoxTag += "<option value='"+ data[i].itemEnName +"'>"+ data[i].itemName +"</option>";
    }

    console.log(_data)
  });
});

$('#htmlBox').on('click', '.dragItem', function(){
  // console.log(selectedDom.find('.dragItemInfo').html())
  console.log(selectedDom.data('type'))

  switch(selectedDom.data('type')){
    case 'TextBoxTag':
      renderProp_TextBoxTag(selectedDom);
      break;
    case 'HiddenBoxTag':
      renderProp_HiddenBoxTag(selectedDom);
      break;
    case 'TextAreaBoxTag':
      renderProp_TextAreaBoxTag(selectedDom);
      break;
    case 'SelectBoxTag':
      renderProp_SelectBoxTag(selectedDom);
      break;
    case 'RadioBoxTag':
      renderProp_RadioBoxTag(selectedDom);
      break;
    case 'CheckBoxTag':
      renderProp_CheckBoxTag(selectedDom);
      break;
    case 'DateBoxTag':
      renderProp_DateBoxTag(selectedDom);
      break;
    case 'DividerBoxTag':
      renderProp_DividerBoxTag(selectedDom);
      break;
    case 'UploadifyBoxTag':
      renderProp_UploadifyBoxTag(selectedDom);
      break;
    default:
      alert('类型错误')
      break;
  }
});

/**
 * 渲染 TextBoxTag
 *
 * @return
 */
function renderProp_TextBoxTag(selectedDom){
  // alert('text')
  // name 属性下拉框
  $("#sel_name").html("");
  $("#sel_name").append($("<option value=''>请选择</option>"));
  if(_data.TextBoxTag){
    $("#sel_name").append($(_data.TextBoxTag));
  }

  // console.log($(selectedDom).data('xml_onclick').js_event)
  // console.log(typeof $(selectedDom).data('xml_onclick'))

  // 绑定
  $("#sel_name option[value='"+ $(selectedDom).data('xml_name') +"']").attr("selected", "selected");

  if($(selectedDom).data('xml_validate')){
    // 绑定
    if('string' === typeof $(selectedDom).data('xml_validate')){
      var ddss = JSON.parse($(selectedDom).data('xml_validate'));
      $("#xml_validate_required").val(ddss.required);
      $("#xml_validate_msg").val(ddss.msg);
    }else{
      $("#xml_validate_required").val($(selectedDom).data('xml_validate').required);
      // $("#xml_validate_required option[value='"+ $(selectedDom).data('xml_validate').required +"']").attr("selected", "selected");
      $("#xml_validate_msg").val($(selectedDom).data('xml_validate').msg);
    }
  }

  // 绑定
  $("#xml_size input").val($(selectedDom).data('xml_size'));
  $("#xml_length input").val($(selectedDom).find('input').attr('_maxLength') || '0-30');

  if($(selectedDom).data('xml_onclick')){
    // 绑定
    if('string' === typeof $(selectedDom).data('xml_onclick')){
      var ssdd = JSON.parse($(selectedDom).data('xml_onclick'));
      $("#xml_onclick_event").val(ssdd.js_event);
      $("#xml_onclick_func").val(ssdd.js_function);
    }else{
      $("#xml_onclick_event").val($(selectedDom).data('xml_onclick').js_event);
      $("#xml_onclick_func").val($(selectedDom).data('xml_onclick').js_function);
    }
  }
  // $("#xml_onclick_event option[value='"+ $(selectedDom).data('xml_onclick').js_event +"']").attr("selected", "selected");
  // $("#xml_onclick_func option[value='"+ $(selectedDom).data('xml_onclick').js_function +"']").attr("selected", "selected");

  // 绑定
  $("#xml_dateFmt select").val($(selectedDom).data('xml_datefmt'));
  $("#xml_dataValue input").val($(selectedDom).data('xml_datavalue'));

  // 绑定
  $("#isReadonly input").attr("checked", $(selectedDom).data('xml_readonly'));
}

function renderProp_HiddenBoxTag(selectedDom){
  // alert('text')
  // name 属性下拉框
  $("#sel_name").html("");
  $("#sel_name").append($("<option value=''>请选择</option>"));
  if(_data.HiddenBoxTag){
    $("#sel_name").append($(_data.HiddenBoxTag));
  }

  // 绑定
  $("#sel_name option[value='"+ $(selectedDom).data('xml_name') +"']").attr("selected", "selected");

  if($(selectedDom).data('xml_validate')){
    // 绑定
    if('string' === typeof $(selectedDom).data('xml_validate')){
      var ddss = JSON.parse($(selectedDom).data('xml_validate'));
      $("#xml_validate_required").val(ddss.required);
      $("#xml_validate_msg").val(ddss.msg);
    }else{
      $("#xml_validate_required").val($(selectedDom).data('xml_validate').required);
      // $("#xml_validate_required option[value='"+ $(selectedDom).data('xml_validate').required +"']").attr("selected", "selected");
      $("#xml_validate_msg").val($(selectedDom).data('xml_validate').msg);
    }
  }

  // 绑定
  $("#xml_size input").val($(selectedDom).data('xml_size'));
  $("#xml_length input").val($(selectedDom).find('input').attr('_maxLength') || '0-30');

  if($(selectedDom).data('xml_onclick')){
    // 绑定
    if('string' === typeof $(selectedDom).data('xml_onclick')){
      var ssdd = JSON.parse($(selectedDom).data('xml_onclick'));
      $("#xml_onclick_event").val(ssdd.js_event);
      $("#xml_onclick_func").val(ssdd.js_function);
    }else{
      $("#xml_onclick_event").val($(selectedDom).data('xml_onclick').js_event);
      $("#xml_onclick_func").val($(selectedDom).data('xml_onclick').js_function);
    }
  }
  // $("#xml_onclick_event option[value='"+ $(selectedDom).data('xml_onclick').js_event +"']").attr("selected", "selected");
  // $("#xml_onclick_func option[value='"+ $(selectedDom).data('xml_onclick').js_function +"']").attr("selected", "selected");

  // 绑定
  $("#xml_dateFmt select").val($(selectedDom).data('xml_datefmt'));
  $("#xml_dataValue input").val($(selectedDom).data('xml_datavalue'));

  // 绑定
  $("#isReadonly input").attr("checked", $(selectedDom).data('xml_readonly'));
}

function renderProp_TextAreaBoxTag(selectedDom){
  // alert('text')
  // name 属性下拉框
  $("#sel_name").html("");
  $("#sel_name").append($("<option value=''>请选择</option>"));
  if(_data.TextAreaBoxTag){
    $("#sel_name").append($(_data.TextAreaBoxTag));
  }

  // 绑定
  $("#sel_name option[value='"+ $(selectedDom).data('xml_name') +"']").attr("selected", "selected");

  if($(selectedDom).data('xml_validate')){
    // 绑定
    if('string' === typeof $(selectedDom).data('xml_validate')){
      var ddss = JSON.parse($(selectedDom).data('xml_validate'));
      $("#xml_validate_required").val(ddss.required);
      $("#xml_validate_msg").val(ddss.msg);
    }else{
      $("#xml_validate_required").val($(selectedDom).data('xml_validate').required);
      // $("#xml_validate_required option[value='"+ $(selectedDom).data('xml_validate').required +"']").attr("selected", "selected");
      $("#xml_validate_msg").val($(selectedDom).data('xml_validate').msg);
    }
  }

  // 绑定
  $("#xml_size input").val($(selectedDom).data('xml_size'));
  $("#xml_length input").val($(selectedDom).find('textarea').attr('_maxLength') || '0-30');
  $("#textPlaceHolder input").val($(selectedDom).find('textarea').attr('placeholder'));

  if($(selectedDom).data('xml_onclick')){
    // 绑定
    if('string' === typeof $(selectedDom).data('xml_onclick')){
      var ssdd = JSON.parse($(selectedDom).data('xml_onclick'));
      $("#xml_onclick_event").val(ssdd.js_event);
      $("#xml_onclick_func").val(ssdd.js_function);
    }else{
      $("#xml_onclick_event").val($(selectedDom).data('xml_onclick').js_event);
      $("#xml_onclick_func").val($(selectedDom).data('xml_onclick').js_function);
    }
  }
  // $("#xml_onclick_event option[value='"+ $(selectedDom).data('xml_onclick').js_event +"']").attr("selected", "selected");
  // $("#xml_onclick_func option[value='"+ $(selectedDom).data('xml_onclick').js_function +"']").attr("selected", "selected");

  // 绑定
  $("#xml_dateFmt select").val($(selectedDom).data('xml_datefmt'));
  $("#xml_dataValue input").val($(selectedDom).data('xml_datavalue'));

  // 绑定
  $("#isReadonly input").attr("checked", $(selectedDom).data('xml_readonly'));
}

function renderProp_UploadifyBoxTag(selectedDom){
  // alert('text')
  // name 属性下拉框
  $("#sel_name").html("");
  $("#sel_name").append($("<option value=''>请选择</option>"));
  if(_data.UploadifyBoxTag){
    $("#sel_name").append($(_data.UploadifyBoxTag));
  }

  $("#sel_datasource").html("");
  $("#sel_datasource").append($("<option value=''>请选择</option>"));
  if(_data.dataSource){
    $("#sel_datasource").append($(_data.dataSource));
  }

  // var s = selectedDom.find('.dragItemInfo').find('span')[1];
  $('#textName input').val(selectedDom.data('xml_title'));
  // console.log(selectedDom.data('xml_title'))

  // 绑定
  $("#sel_name option[value='"+ $(selectedDom).data('xml_name') +"']").attr("selected", "selected");

  $("#sel_datasource option[value='"+ $(selectedDom).data('xml_datafrom') +"']").attr("selected", "selected");

  if($(selectedDom).data('xml_validate')){
    // 绑定
    if('string' === typeof $(selectedDom).data('xml_validate')){
      var ddss = JSON.parse($(selectedDom).data('xml_validate'));
      $("#xml_validate_required").val(ddss.required);
      $("#xml_validate_msg").val(ddss.msg);
    }else{
      $("#xml_validate_required").val($(selectedDom).data('xml_validate').required);
      // $("#xml_validate_required option[value='"+ $(selectedDom).data('xml_validate').required +"']").attr("selected", "selected");
      $("#xml_validate_msg").val($(selectedDom).data('xml_validate').msg);
    }
  }

  // 绑定
  $("#xml_size input").val($(selectedDom).data('xml_size'));
  $("#xml_length input").val($(selectedDom).data('xml_length'));

  if($(selectedDom).data('xml_onclick')){
    // 绑定
    if('string' === typeof $(selectedDom).data('xml_onclick')){
      var ssdd = JSON.parse($(selectedDom).data('xml_onclick'));
      $("#xml_onclick_event").val(ssdd.js_event);
      $("#xml_onclick_func").val(ssdd.js_function);
    }else{
      $("#xml_onclick_event").val($(selectedDom).data('xml_onclick').js_event);
      $("#xml_onclick_func").val($(selectedDom).data('xml_onclick').js_function);
    }
  }
  // $("#xml_onclick_event option[value='"+ $(selectedDom).data('xml_onclick').js_event +"']").attr("selected", "selected");
  // $("#xml_onclick_func option[value='"+ $(selectedDom).data('xml_onclick').js_function +"']").attr("selected", "selected");

  // 绑定
  $("#xml_dateFmt select").val($(selectedDom).data('xml_datefmt'));
  $("#xml_dataValue input").val($(selectedDom).data('xml_datavalue'));

  $("#textPlaceHolder input").val($(selectedDom).data('xml_tips'));
}

function renderProp_SelectBoxTag(selectedDom){
  $("#sel_name").html("");
  $("#sel_name").append($("<option value=''>请选择</option>"));
  if(_data.SelectBoxTag){
    $("#sel_name").append($(_data.SelectBoxTag));
  }

  $("#sel_datasource").html("");
  $("#sel_datasource").append($("<option value=''>请选择</option>"));
  if(_data.dataSource){
    $("#sel_datasource").append($(_data.dataSource));
  }

  // 绑定
  $("#sel_name option[value='"+ $(selectedDom).data('xml_name') +"']").attr("selected", "selected");

  if($(selectedDom).data('xml_validate')){
    // 绑定
    if('string' === typeof $(selectedDom).data('xml_validate')){
      var ddss = JSON.parse($(selectedDom).data('xml_validate'));
      $("#xml_validate_required").val(ddss.required);
      $("#xml_validate_msg").val(ddss.msg);
    }else{
      $("#xml_validate_required").val($(selectedDom).data('xml_validate').required);
      // $("#xml_validate_required option[value='"+ $(selectedDom).data('xml_validate').required +"']").attr("selected", "selected");
      $("#xml_validate_msg").val($(selectedDom).data('xml_validate').msg);
    }
  }

  // 绑定
  $("#xml_size input").val($(selectedDom).data('xml_size'));
  $("#xml_length input").val($(selectedDom).find('textarea').attr('_maxLength'));

  if($(selectedDom).data('xml_onclick')){
    // 绑定
    if('string' === typeof $(selectedDom).data('xml_onclick')){
      var ssdd = JSON.parse($(selectedDom).data('xml_onclick'));
      $("#xml_onclick_event").val(ssdd.js_event);
      $("#xml_onclick_func").val(ssdd.js_function);
    }else{
      $("#xml_onclick_event").val($(selectedDom).data('xml_onclick').js_event);
      $("#xml_onclick_func").val($(selectedDom).data('xml_onclick').js_function);
    }
  }
  // $("#xml_onclick_event option[value='"+ $(selectedDom).data('xml_onclick').js_event +"']").attr("selected", "selected");
  // $("#xml_onclick_func option[value='"+ $(selectedDom).data('xml_onclick').js_function +"']").attr("selected", "selected");

  // 绑定
  $("#xml_dateFmt select").val($(selectedDom).data('xml_datefmt'));
  $("#xml_dataValue input").val($(selectedDom).data('xml_datavalue'));

  // 绑定
  $("#isReadonly input").attr("checked", $(selectedDom).data('xml_readonly'));

  $("#sel_datasource option[value='"+ $(selectedDom).data('xml_datafrom') +"']").attr("selected", "selected");
}

function renderProp_RadioBoxTag(selectedDom){
  $("#sel_name").html("");
  $("#sel_name").append($("<option value=''>请选择</option>"));
  if(_data.RadioBoxTag){
    $("#sel_name").append($(_data.RadioBoxTag));
  }


  $("#sel_datasource").html("");
  $("#sel_datasource").append($("<option value=''>请选择</option>"));
  if(_data.dataSource){
    $("#sel_datasource").append($(_data.dataSource));
  }

  // 绑定
  $("#sel_name option[value='"+ $(selectedDom).data('xml_name') +"']").attr("selected", "selected");

  if($(selectedDom).data('xml_validate')){
    // 绑定
    if('string' === typeof $(selectedDom).data('xml_validate')){
      var ddss = JSON.parse($(selectedDom).data('xml_validate'));
      $("#xml_validate_required").val(ddss.required);
      $("#xml_validate_msg").val(ddss.msg);
    }else{
      $("#xml_validate_required").val($(selectedDom).data('xml_validate').required);
      // $("#xml_validate_required option[value='"+ $(selectedDom).data('xml_validate').required +"']").attr("selected", "selected");
      $("#xml_validate_msg").val($(selectedDom).data('xml_validate').msg);
    }
  }

  // 绑定
  $("#xml_size input").val($(selectedDom).data('xml_size'));
  $("#xml_length input").val($(selectedDom).find('textarea').attr('_maxLength'));

  if($(selectedDom).data('xml_onclick')){
    // 绑定
    if('string' === typeof $(selectedDom).data('xml_onclick')){
      var ssdd = JSON.parse($(selectedDom).data('xml_onclick'));
      $("#xml_onclick_event").val(ssdd.js_event);
      $("#xml_onclick_func").val(ssdd.js_function);
    }else{
      $("#xml_onclick_event").val($(selectedDom).data('xml_onclick').js_event);
      $("#xml_onclick_func").val($(selectedDom).data('xml_onclick').js_function);
    }
  }
  // $("#xml_onclick_event option[value='"+ $(selectedDom).data('xml_onclick').js_event +"']").attr("selected", "selected");
  // $("#xml_onclick_func option[value='"+ $(selectedDom).data('xml_onclick').js_function +"']").attr("selected", "selected");

  // 绑定
  $("#xml_dateFmt select").val($(selectedDom).data('xml_datefmt'));
  $("#xml_dataValue input").val($(selectedDom).data('xml_datavalue'));

  // 绑定
  $("#isReadonly input").attr("checked", $(selectedDom).data('xml_readonly'));

  $("#sel_datasource option[value='"+ $(selectedDom).data('xml_datafrom') +"']").attr("selected", "selected");
}

function renderProp_CheckBoxTag(selectedDom){
  $("#sel_name").html("");
  $("#sel_name").append($("<option value=''>请选择</option>"));
  if(_data.CheckBoxTag){
    $("#sel_name").append($(_data.CheckBoxTag));
  }

  $("#sel_datasource").html("");
  $("#sel_datasource").append($("<option value=''>请选择</option>"));
  if(_data.dataSource){
    $("#sel_datasource").append($(_data.dataSource));
  }

  // 绑定
  $("#sel_name option[value='"+ $(selectedDom).data('xml_name') +"']").attr("selected", "selected");

  if($(selectedDom).data('xml_validate')){
    // 绑定
    if('string' === typeof $(selectedDom).data('xml_validate')){
      var ddss = JSON.parse($(selectedDom).data('xml_validate'));
      $("#xml_validate_required").val(ddss.required);
      $("#xml_validate_msg").val(ddss.msg);
    }else{
      $("#xml_validate_required").val($(selectedDom).data('xml_validate').required);
      // $("#xml_validate_required option[value='"+ $(selectedDom).data('xml_validate').required +"']").attr("selected", "selected");
      $("#xml_validate_msg").val($(selectedDom).data('xml_validate').msg);
    }
  }

  // 绑定
  $("#xml_size input").val($(selectedDom).data('xml_size'));
  $("#xml_length input").val($(selectedDom).find('textarea').attr('_maxLength'));

  if($(selectedDom).data('xml_onclick')){
    // 绑定
    if('string' === typeof $(selectedDom).data('xml_onclick')){
      var ssdd = JSON.parse($(selectedDom).data('xml_onclick'));
      $("#xml_onclick_event").val(ssdd.js_event);
      $("#xml_onclick_func").val(ssdd.js_function);
    }else{
      $("#xml_onclick_event").val($(selectedDom).data('xml_onclick').js_event);
      $("#xml_onclick_func").val($(selectedDom).data('xml_onclick').js_function);
    }
  }
  // $("#xml_onclick_event option[value='"+ $(selectedDom).data('xml_onclick').js_event +"']").attr("selected", "selected");
  // $("#xml_onclick_func option[value='"+ $(selectedDom).data('xml_onclick').js_function +"']").attr("selected", "selected");

  // 绑定
  $("#xml_dateFmt select").val($(selectedDom).data('xml_datefmt'));
  $("#xml_dataValue input").val($(selectedDom).data('xml_datavalue'));

  // 绑定
  $("#isReadonly input").attr("checked", $(selectedDom).data('xml_readonly'));

  $("#sel_datasource option[value='"+ $(selectedDom).data('xml_datafrom') +"']").attr("selected", "selected");
}

function renderProp_DividerBoxTag(selectedDom){
  $("#sel_datasource").html("");
  $("#sel_datasource").append($("<option value=''>请选择</option>"));
  if(_data.DividerBoxTag){
    $("#sel_datasource").append($(_data.DividerBoxTag));
  }

  // 绑定
  $("#sel_datasource option[value='"+ $(selectedDom).data('xml_datafrom') +"']").attr("selected", "selected");

  // $('#inputName').css('display', 'none')
  $("#sel_name").html("");
  $("#sel_name").append($("<option value=''>请选择</option>"));
}

function renderProp_DateBoxTag(selectedDom){
  $("#sel_name").html("");
  $("#sel_name").append($("<option value=''>请选择</option>"));
  if(_data.DateBoxTag){
    $("#sel_name").append($(_data.DateBoxTag));
  }

  // 绑定
  $("#sel_name option[value='"+ $(selectedDom).data('xml_name') +"']").attr("selected", "selected");

  if($(selectedDom).data('xml_validate')){
    // 绑定
    if('string' === typeof $(selectedDom).data('xml_validate')){
      var ddss = JSON.parse($(selectedDom).data('xml_validate'));
      $("#xml_validate_required").val(ddss.required);
      $("#xml_validate_msg").val(ddss.msg);
    }else{
      $("#xml_validate_required").val($(selectedDom).data('xml_validate').required);
      // $("#xml_validate_required option[value='"+ $(selectedDom).data('xml_validate').required +"']").attr("selected", "selected");
      $("#xml_validate_msg").val($(selectedDom).data('xml_validate').msg);
    }
  }

  // 绑定
  $("#xml_size input").val($(selectedDom).data('xml_size'));
  $("#xml_length input").val($(selectedDom).find('textarea').attr('_maxLength'));

  if($(selectedDom).data('xml_onclick')){
    // 绑定
    if('string' === typeof $(selectedDom).data('xml_onclick')){
      var ssdd = JSON.parse($(selectedDom).data('xml_onclick'));
      $("#xml_onclick_event").val(ssdd.js_event);
      $("#xml_onclick_func").val(ssdd.js_function);
    }else{
      $("#xml_onclick_event").val($(selectedDom).data('xml_onclick').js_event);
      $("#xml_onclick_func").val($(selectedDom).data('xml_onclick').js_function);
    }
  }
  // $("#xml_onclick_event option[value='"+ $(selectedDom).data('xml_onclick').js_event +"']").attr("selected", "selected");
  // $("#xml_onclick_func option[value='"+ $(selectedDom).data('xml_onclick').js_function +"']").attr("selected", "selected");

  // 绑定
  $("#xml_dateFmt select").val($(selectedDom).data('xml_datefmt'));
  $("#xml_dataValue input").val($(selectedDom).data('xml_datavalue'));

  // 绑定
  $("#isReadonly input").attr("checked", $(selectedDom).data('xml_readonly'));
}

/**
 * 检测表单元素属性
 * @return
 */
function checkShow(){
  return;
}

function showMeKeys(xml){
  var str = '';

  $(xml).find('inputAttribute').each(function(){
    switch($(this).attr('type')){
      case 'DividerBoxTag':
        break;
      default:
        str += $(this).children('id').text() +','
        break;
    }
  });

  if(0 < str.length){
    str = str.substring(0, str.length - 1)
  }

  return str;
}

function showMe(){
  var check = checkShow();
  if(check){
    alert(check);
    return;
  }

  // var i = 0;

  var str = '<?xml version="1.0" encoding="UTF-8"?>'
  str += '<formconstructor>'

  try{
    $('.dragBox').each(function(){
      var a = $(this).children()[0];
      // console.log($(a).data('type'))

      // console.log($(a).find('span .dragItemInfo').text())

      var __xml = genXml(a);

      if('object' === typeof __xml){
         throw  __xml.msg ;
      }

      str += __xml;
      // i++;
    })
  }catch(e){
    return alert(e)
  }

  str += '</formconstructor>';

  // console.log(i)
  // console.log(str)
  return str;
}

function checkData_TextBoxTag(a, type){
  switch(type){
    case 'title':
      var val = ($(a).data('xml_title') || '');
      return ('' === val) ? {msg: '请选择文本名称'} : val;
    case 'id':
      var val = ($(a).data('xml_id') || '');
      return ('' === val) ? {msg: '请选择标签名'} : val;
    default:
      return ''
  }
}

function checkData_HiddenBoxTag(a, type){
  switch(type){
    case 'title':
      var val = ($(a).data('xml_title') || '');
      return ('' === val) ? {msg: '请选择文本名称'} : val;
    case 'id':
      var val = ($(a).data('xml_id') || '');
      return ('' === val) ? {msg: '请选择标签名'} : val;
    default:
      return ''
  }
}

function checkData_TextAreaBoxTag(a, type){
  switch(type){
    case 'title':
      var val = ($(a).data('xml_title') || '');
      return ('' === val) ? {msg: '请选择文本名称'} : val;
    case 'id':
      var val = ($(a).data('xml_id') || '');
      return ('' === val) ? {msg: '请选择标签名'} : val;
    default:
      return ''
  }
}

function checkData_SelectBoxTag(a, type){
  switch(type){
    case 'title':
      var val = ($(a).data('xml_title') || '');
      return ('' === val) ? {msg: '请选择文本名称'} : val;
    case 'id':
      var val = ($(a).data('xml_id') || '');
      return ('' === val) ? {msg: '请选择标签名'} : val;
    default:
      return ''
  }
}

function checkData_DateBoxTag(a, type){
  switch(type){
    case 'title':
      var val = ($(a).data('xml_title') || '');
      return ('' === val) ? {msg: '请选择文本名称'} : val;
    case 'id':
      var val = ($(a).data('xml_id') || '');
      return ('' === val) ? {msg: '请选择标签名'} : val;
    default:
      return ''
  }
}

function checkData_UploadifyBoxTag(a, type){
  switch(type){
    case 'title':
      var val = ($(a).data('xml_title') || '');
      return ('' === val) ? {msg: '请选择文本名称'} : val;
    case 'id':
      var val = ($(a).data('xml_id') || '');
      return ('' === val) ? {msg: '请选择标签名'} : val;
    default:
      return ''
  }
}

function checkData_RadioBoxTag(a, type){
  switch(type){
    case 'title':
      var val = ($(a).data('xml_title') || '');
      return ('' === val) ? {msg: '请选择文本名称'} : val;
    case 'id':
      var val = ($(a).data('xml_id') || '');
      return ('' === val) ? {msg: '请选择标签名'} : val;
    default:
      return ''
  }
}

function checkData_CheckBoxTag(a, type){
  switch(type){
    case 'title':
      var val = ($(a).data('xml_title') || '');
      return ('' === val) ? {msg: '请选择文本名称'} : val;
    case 'id':
      var val = ($(a).data('xml_id') || '');
      return ('' === val) ? {msg: '请选择标签名'} : val;
    default:
      return ''
  }
}

function checkData(a, type){
  switch($(a).data('type')){
    case 'TextBoxTag':
      return checkData_TextBoxTag(a, type);
    case 'HiddenBoxTag':
      return checkData_HiddenBoxTag(a, type);
    case 'TextAreaBoxTag':
      return checkData_TextAreaBoxTag(a, type);
    case 'SelectBoxTag':
      return checkData_SelectBoxTag(a, type);
    case 'DateBoxTag':
      return checkData_DateBoxTag(a, type);
    case 'UploadifyBoxTag':
      return checkData_UploadifyBoxTag(a, type);
    case 'RadioBoxTag':
      return checkData_RadioBoxTag(a, type);
    case 'CheckBoxTag':
      return checkData_CheckBoxTag(a, type);
      
    default:
      return ''
  }
}


function genXml(a){
  str = '<inputAttribute type="'+ $(a).data('type') +'">';

  // alert($(a).data('xml_flow'))

  // str += '<title>'+ $(a).find('span .dragItemInfo').text() +'</title>';
  // str += '<id>'+ proc_id(a) +'</id>';
  // str += '<name>'+ proc_name(a) +'</name>';

  {
  var __id = checkData(a, 'id');
  if('object' === typeof __id){
    return __id;
  }

  str += '<id>'+ __id +'</id>';
  }

  {
  var __title = checkData(a, 'title');
  if('object' === typeof __title){
    return __title;
  }

  str += '<title>'+ __title +'</title>';
  }

  str += '<name>'+ ($(a).data('xml_name') || '') +'</name>';
  str += '<size>'+ proc_size(a) +'</size>';

  if('string' === typeof($(a).data('xml_validate')))
    str += '<validate>'+ $(a).data('xml_validate') +'</validate>';
  else
    str += '<validate>'+ JSON.stringify($(a).data('xml_validate')) +'</validate>';

  str += '<length>'+ proc_length(a) +'</length>';
  str += '<readonly>'+ ($(a).data('xml_readonly') || false) +'</readonly>';
  str += '<tips>'+ proc_tips(a) +'</tips>';

  if('string' === typeof($(a).data('xml_onclick')))
    str += '<onclick>'+ $(a).data('xml_onclick') +'</onclick>';
  else
    str += '<onclick>'+ JSON.stringify($(a).data('xml_onclick')) +'</onclick>';


  str += '<dateFmt>'+ $(a).data('xml_datefmt') +'</dateFmt>';
  str += '<dataFrom>'+ $(a).data('xml_datafrom') +'</dataFrom>';
  str += '<dataValue>'+ $(a).data('xml_datavalue') +'</dataValue>';
  // str += '<flow>'+ $(a).data('xml_flow') +'</flow>';
  str += '<flow>{"flowid":"402881964f4efbb9014f4f11f6600028","hidden":"","readonly":"","setvalue":""}</flow>';
  str += '<others/>'

  str += '</inputAttribute>';
  return str;
}

function proc_tips(a){
  switch($(a).data('type')){
    case 'TextBoxTag':
      return $(a).find('input').attr('placeholder')
    case 'HiddenBoxTag':
      return $(a).find('input').attr('placeholder')
    case 'TextAreaBoxTag':
      return $(a).find('textarea').attr('placeholder')
    case 'SelectBoxTag':
      return $(a).data('xml_tips')
    case 'DateBoxTag':
      return ''
    case 'UploadifyBoxTag':
      return $(a).data('xml_tips')
    case 'RadioBoxTag':
      return $(a).data('xml_tips')
    case 'CheckBoxTag':
      return $(a).data('xml_tips')
    default:
      return ''
  }
}

function proc_id(a){
  switch($(a).data('type')){
    case 'TextBoxTag':
      return $(a).find('input').attr('name')
    default:
      return ''
  }
}

function proc_name(a){
  switch($(a).data('type')){
    case 'TextBoxTag':
      return $(a).find('input').attr('name')
    default:
      return ''
  }
}

function proc_size(a){
  switch($(a).data('type')){
    case 'TextBoxTag':
      return $(a).data('xml_size');
    case 'HiddenBoxTag':
      return $(a).data('xml_size');
    case 'TextAreaBoxTag':
      return $(a).data('xml_size');
    default:
      return '0'
  }
}

function proc_length(a){
  switch($(a).data('type')){
    case 'TextBoxTag':
      return $(a).find('input').attr('_maxLength');
    case 'HiddenBoxTag':
      return $(a).find('input').attr('_maxLength');
    case 'TextAreaBoxTag':
      return $(a).find('textarea').attr('_maxLength');
    case 'DateBoxTag':
      return '';
    default:
      return '0'
  }
}

$(function(){
  bindEvt();
})

function bindEvt(){
  bind_readonly();
  bind_sel_name();
}

function bind_readonly(){
  // console.log($('#isReadonly'))

  $('#isReadonly').click(function(){
    if(!selectedDom) return;
    // console.log(selectedDom.data('type'))
    // console.log($(this).find('input').is(':checked'))
    selectedDom.data('xml_readonly', $(this).find('input').is(':checked'));
  })
}

function bind_sel_name(){
  $('#sel_name').change(function(){
    if(!selectedDom) return;
    var v1 = $(this).children('option:selected').val();
    var v2 = $(this).children('option:selected').text();
    if(!v1) return alert('请选择标签名');

    // console.log(v1);
    selectedDom.find('.dragItemInfo').html(v2 +':')
    $('#textName input').val(v2 +':')
    selectedDom.data('xml_id', v1);
    selectedDom.data('xml_name', v1);
  })
}

// $(function(){
//   var data = '[{"tagName":"DIV","class":{"0":"dragBox"},"style":"","tagAttr":{},"children":[{"tagName":"DIV","class":{"0":"form-group","1":"dragItem","2":"selectedEle"},"style":"display: inline-block; vertical-align: top; padding: 5px; font-size: 14px; color: rgb(51, 51, 51); margin-left: 0px; margin-top: 0px;","tagAttr":{},"children":[{"tagName":"SPAN","class":{"0":"dragItemInfoBox"},"style":"margin-bottom: 0;width: 80px;text-align: right;display: inline-block;","tagAttr":{},"children":[{"tagName":"SPAN","class":{"0":"isRequiredImg"},"style":"vertical-align: middle;display: none;color: red;font-size: 20px;margin-top: 6px;","tagAttr":{},"children":[],"text":"*"},{"tagName":"SPAN","class":{"0":"dragItemInfo"},"style":"font-weight: 100;","tagAttr":{},"children":[],"text":"文本框:"}]},{"tagName":"DIV","class":{},"style":"display: inline-block;vertical-align: middle;","tagAttr":{},"children":[{"tagName":"INPUT","class":{"0":"form-control","1":"input-sm","2":"commonType","3":"inputName"},"style":"display: inline-block;width: 160px;","tagAttr":{"name":"123","type":"text","placeholder":"123"},"children":[]}]}]}]}]'
//   var dataJ = JSON.parse(data);
//   console.log(dataJ);
//   var $htmlBox = $("#htmlBox");

//   var wer = 1;

//   function eleCreate(data, parent) {
//       if (!data) return true;
//       console.log(wer++);
//       var parent = parent || $(body);
//       var ele = null;
//       var $ele = null;
//       ele = document.createElement(data.tagName);
//       $ele = $(ele);
//       $.each(data.class, function (kC, vC) {
//           if (vC === 'dragItem') {
//               $ele.attr('draggable', true)
//               $ele.removeClass('selectedEle')
//           }
//           if (vC !== 'selectedEle') {
//               $ele.addClass(vC)
//           }
//       });
//       ele.style = data.style;
//       $.each(data.tagAttr, function (kT, vT) {
//           $ele.attr(kT, vT)
//       });
//       $.each(data.children, function (kCH, vCH) {
//           eleCreate(vCH, $ele);
//       });
//       // })
//       if (data.text) $ele.html(data.text);
//       parent.append(ele);
//   }

//   for (var i = 0; i < dataJ.length; i++) {
//       var obj = dataJ[i];
//       eleCreate(obj, $htmlBox);
//   }

//       // $htmlBox.append($("<p>121</p>"))
// })


$(function(){

  function createCustomData(src){
    return 'data-xml_length=\''+ src.children('length').text() +'\' data-xml_datavalue=\''+ src.children('dataValue').text() +'\' data-xml_datafrom=\''+ src.children('dataFrom').text() +'\' data-xml_dateFmt=\''+ src.children('dateFmt').text() +'\' data-xml_tips=\''+ src.children('tips').text() +'\' data-xml_readonly=\''+ src.children('readonly').text() +'\' data-xml_size=\''+ src.children('size').text() +'\' data-xml_onclick=\''+ src.children('onclick').text() +'\' data-xml_validate=\''+ src.children('validate').text() +'\' data-xml_id="'+ src.children('id').text() +'" data-xml_name="'+ src.children('name').text() +'" data-xml_title="'+ src.children('title').text() +'"'
  }

  /**
   *
   */
  function createTextBoxTag(src){
    var str = '<div class="dragBox" style="">'
    str +=      '<div '+ createCustomData(src) +' class="form-group dragItem" data-type="TextBoxTag" inputtype="inputTextType" draggable="true" style="display: inline-block;vertical-align: top;padding:5px;">'
    str +=         '<span style="margin-bottom: 0;width: 80px;text-align: right;display: inline-block;" class="dragItemInfoBox">'
    str +=            '<span class="isRequiredImg" style="vertical-align: middle;display: none;color: red;font-size: 20px;margin-top: 6px;">*</span>'
    str +=            '<span class="dragItemInfo">'+ src.children('title').text() +'</span>'
    str +=          '</span>'
    str +=          '<div style="display: inline-block;vertical-align: middle;">'
    str +=            '<input placeholder="'+ src.children('tips').text() +'" _maxLength="'+ src.children('length').text() +'" type="text" class="form-control input-sm commonType inputName" style="display: inline-block;width: 160px;">'
    str +=          '</div>'
    str +=        '</div></div>';
    return str;
  }

  /**
   *
   */
  function createSelectBoxTag(src){
    var str = '<div class="dragBox" style="">'
    str +=      '<div '+ createCustomData(src) +' class="form-group dragItem" data-type="SelectBoxTag" inputtype="selectType" dataattr="select" draggable="true" style="display: inline-block;vertical-align: top;padding:5px;">'
    str +=        '<span class="dragItemInfo" style="margin-bottom: 0;width: 80px;text-align: right;display: inline-block;">'+ src.children('title').text() +'</span>'
    str +=        '<div style="display: inline-block;vertical-align: middle;">'
    str +=          '<select name="" id="" class="form-control input-sm inputName" style="width: 100px;">'
    str +=            '<option value="">北京</option>'
    str +=            '<option value="">上海</option>'
    str +=          '</select>'
    str +=        '</div>'
    str +=      '</div></div>';
    return str;
  }

  /**
   *
   */
  function createDividerBoxTag(src){
    var str = '<div class="dragBox" style="">'
    str +=      '<div '+ createCustomData(src) +' class="form-group dragItem wordContent" data-type="DividerBoxTag" inputtype="dividerType" draggable="true" style="display: inline-block;vertical-align: top;padding:5px 10px;">'
    str +=      '<span class="dragItemInfo " style="margin-bottom: 0;text-align: right;display: inline-block;">'+ src.children('title').text() +'</span>'
    str +=      '</div></div>'
    return str;
  }

  /**
   *
   */
  function createHiddenBoxTag(src){
    var str = '<div class="dragBox" style="">'
    str +=      '<div '+ createCustomData(src) +' class="form-group dragItem" data-type="HiddenBoxTag" inputtype="inputTextType" draggable="true" style="display: inline-block;vertical-align: top;padding:5px;">'
    str +=        '<span style="margin-bottom: 0;width: 80px;text-align: right;display: inline-block;" class="dragItemInfoBox">'
    str +=          '<span class="isRequiredImg" style="vertical-align: middle;display: none;color: red;font-size: 20px;margin-top: 6px;">*</span>'
    str +=          '<span class="dragItemInfo">'+ src.children('title').text() +'</span>'
    str +=        '</span>'
    str +=        '<div style="display: inline-block;vertical-align: middle;">'
    str +=          '<input placeholder="'+ src.children('tips').text() +'" _maxLength="'+ src.children('length').text() +'" type="text" class="form-control input-sm inputName" style="display: inline-block;width: 160px;">'
    str +=        '</div>'
    str +=      '</div></div>'
    return str;
  }

  /**
   *
   */
  function createTextAreaBoxTag(src){
    var str = '<div class="dragBox" style="">'
    str +=      '<div '+ createCustomData(src) +' class="form-group dragItem" data-type="TextAreaBoxTag" inputtype="inputTextType" draggable="true" style="display: inline-block;vertical-align: top;padding:5px;">'
    str +=        '<span style="margin-bottom: 0;width: 80px;text-align: right;display: inline-block;" class="dragItemInfoBox">'
    str +=          '<span class="isRequiredImg" style="vertical-align: middle;display: none;color: red;font-size: 20px;margin-top: 6px;">*</span>'
    str +=          '<span class="dragItemInfo">'+ src.children('title').text() +'</span>'
    str +=        '</span>'
    str +=        '<div style="display: inline-block;vertical-align: top;">'
    str +=          '<textarea placeholder="'+ src.children('tips').text() +'" _maxLength="'+ src.children('length').text() +'"  class="form-control input-sm inputName"></textarea>'
    str +=        '</div>'
    str +=      '</div></div>'
    return str;
  }

  /**
   *
   */
  function createDateBoxTag(src){
    var str = '<div class="dragBox" style="">'
    str +=      '<div '+ createCustomData(src) +' class="form-group dragItem " data-type="DateBoxTag" inputtype="dateType" draggable="true" style="display: inline-block;vertical-align: top;padding:5px;">'
    str +=        '<span style="margin-bottom: 0;width: 80px;text-align: right;display: inline-block;" class="dragItemInfoBox">'
    str +=          '<span class="isRequiredImg" style="vertical-align: middle;display: none;color: red;font-size: 20px;margin-top: 6px;">*</span>'
    str +=          '<span class="dragItemInfo">'+ src.children('title').text() +'</span>'
    str +=        '</span>'
    str +=        '<div style="display: inline-block;width: 160px;vertical-align: middle;" class="dateSelector">'
    str +=          '<input type="date">'
    str +=        '</div>'
    str +=      '</div></div>'
    return str;
  }

  /**
   *
   */
  function createRadioBoxTag(src){
    var str = '<div class="dragBox" style="">'
    str +=      '<div '+ createCustomData(src) +' class="form-group dragItem " data-type="RadioBoxTag" inputtype="checkType" dataattr="radio" draggable="true" style="height: 30px;display: inline-block;vertical-align: top;padding:5px;">'
    str +=        '<span class="dragItemInfo" style="margin-bottom: 0;width: 80px;text-align: right;display: inline-block;">'+ src.children('title').text() +'</span>'
    str +=        '<div style="display: inline-block;vertical-align: middle;">'
    str +=          '<label style="margin-left: 10px;"><span>男</span><input type="radio" name="radio" class="inputName" style="margin-left: 5px;vertical-align:top" value="男"></label>'
    str +=          '<label style="margin-left: 10px;"><span>女</span><input type="radio" name="radio" class="inputName" style="margin-left: 5px;vertical-align:top" value="女"></label>'
    str +=        '</div>'
    str +=      '</div></div>'
    return str;
  }

  /**
   *
   */
  function createCheckBoxTag(src){
    var str = '<div class="dragBox" style="">'
    str +=      '<div '+ createCustomData(src) +' class="form-group dragItem " data-type="CheckBoxTag" inputtype="checkType" dataattr="checkbox" draggable="true" style="height: 30px;display: inline-block;vertical-align: top;padding:5px;">'
    str +=        '<span class="dragItemInfo" style="margin-bottom: 0;width: 80px;text-align: right;display: inline-block;">'+ src.children('title').text() +'</span>'
    str +=        '<div style="display: inline-block;vertical-align: middle;">'
    str +=          '<label style="margin-left: 10px;"><span>北京</span><input type="checkbox" class="inputName" name="checkbox1" style="margin-left: 5px;vertical-align:top" value="北京"></label>'
    str +=          '<label style="margin-left: 10px;"><span>上海</span><input type="checkbox" class="inputName" name="checkbox2" style="margin-left: 5px;vertical-align:top" value="上海"></label>'
    str +=        '</div>'
    str +=      '</div></div>'
    return str;
  }

  /**
   *
   */
  function createUploadifyBoxTag(src){
    var str = '<div class="dragBox" style="">'
    str +=      '<div '+ createCustomData(src) +' class="form-group dragItem " data-type="UploadifyBoxTag" inputtype="uploadifyType" draggable="true" style="display: inline-block;vertical-align: top;padding:5px;" inputtype="selectType">'
    str +=        '<span class="dragItemInfo" style="margin-bottom: 0;width: 80px;text-align: right;display: inline-block;">'
    str +=          '<span class="isRequiredImg" style="vertical-align: middle;display: none;color: red;font-size: 20px;margin-top: 6px;">*</span><span>'+ src.children('title').text() +'</span>'
    str +=        '</span>'
    str +=        '<div style="display: inline-block;vertical-align: middle;">'
    str +=          '<input type="file" class="file inputName">'
    str +=        '</div>'
    str +=      '</div></div>'
    return str;
  }


  // var xml = '<formconstructor><inputAttribute type="TextBoxTag"><title>用户名:</title><id>user_name</id><name>user_name</name><size>20</size><validate>{"required":"","msg":""}</validate><length>0</length><readonly>false</readonly><tips></tips><onclick>{"js_event":"","js_function":""}</onclick><dateFmt>yyyy-MM-dd</dateFmt><dataFrom>{b:2}</dataFrom><dataValue></dataValue><flow>{"flowid":"402881964f4efbb9014f4f11f6600028","hidden":"","readonly":"","setvalue":""}</flow><others/></inputAttribute><inputAttribute type="SelectBoxTag"><title>性别:</title><id>sex</id><name>sex</name><size>0</size><validate>{"required":"","msg":""}</validate><length>0</length><readonly>false</readonly><tips></tips><onclick>{"js_event":"","js_function":""}</onclick><dateFmt>yyyy-MM-dd</dateFmt><dataFrom></dataFrom><dataValue></dataValue><flow>{"flowid":"402881964f4efbb9014f4f11f6600028","hidden":"","readonly":"","setvalue":""}</flow><others/></inputAttribute></formconstructor>';

  // console.log(xml)

  // $(xml).find('inputAttribute').each(function(){
  //   console.log($(this).attr('type'));
  //   console.log($(this).children('title').text());
  // });

  var _param_id = (location.search.match(/catalogId=([\w\-]+)/) ? RegExp.$1 : '');
  console.log(_param_id)

  $.ajax({
      url: _url_edit +'?catalogId='+ _param_id +'&rnd='+ Math.random(),
      type: 'GET',
      dataType: 'json',
  }).done(function (data){

    if("1" !== data.code){
      return alert(data.msg);
    }

    $('#buiderHtml').css('display', 'block');

    if('' == data.dataXml) return;

    var str = '';

    $(data.dataXml).find('inputAttribute').each(function(){
      // console.log($(this).attr('type'));
      // console.log($(this).children('title').text());

      switch($(this).attr('type')){
        case 'DividerBoxTag':
          str += createDividerBoxTag($(this));
          break;
        case 'TextBoxTag':
          str += createTextBoxTag($(this));
          break;
        case 'SelectBoxTag':
          str += createSelectBoxTag($(this));
          break;
        case 'HiddenBoxTag':
          str += createHiddenBoxTag($(this));
          break;
        case 'TextAreaBoxTag':
          str += createTextAreaBoxTag($(this));
          break;
        case 'DateBoxTag':
          str += createDateBoxTag($(this));
          break;
        case 'RadioBoxTag':
          str += createRadioBoxTag($(this));
          break;
        case 'CheckBoxTag':
          str += createCheckBoxTag($(this));
          break;
        case 'UploadifyBoxTag':
          str += createUploadifyBoxTag($(this));
          break;
        default:
          break;
      }
    });

    var $htmlBox = $("#htmlBox");
    $htmlBox.append($(str))
    // $htmlBox.html(str)
  });

});

function checkKeyExists(){
  var s = showMeKeys(showMe());
  if('' == s) return false;
  s = ','+ s +',';

  var ss = s.split(',')

  for(var i=0; i<ss.length; i++){
    if('' == ss[i]) continue;

    var sss = ss[i];

    if(s.indexOf(','+ sss +',') != s.lastIndexOf(','+ sss +',')){
      return true;
    }
  }

  return false;
}
